package com.zr.d_c.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.d_c.model.Seller;
import com.zr.d_c.model.User;
import com.zr.d_c.service.UserInfoService;
import com.zr.d_c.service.UserService;
import com.zr.d_c.serviceimpl.UserInfoServiceImpl;
import com.zr.d_c.serviceimpl.UserServiceImpl;
/**
 * 商家删除账户(自己)
 * @author Administrator
 *
 */
public class DeleteSellerController extends HttpServlet{
	UserService sellerservice = new UserServiceImpl();
	UserInfoService sellerinfoservice = new UserInfoServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
     @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession();
    User u = (User) session.getAttribute("currentUser"); 
    PrintWriter pw = resp.getWriter();
    int sid = sellerinfoservice.getSellerSidByUid(u.getUid());    
    String upsw =req.getParameter("upsw");
    String upsw1 = req.getParameter("upsw1");
    if (upsw.equals(upsw1)) {
    	
		if (sellerinfoservice.deleteSinfo(sid)) {
			
			req.getRequestDispatcher("person/deleteuser.jsp").forward(req, resp);
			pw.write("1");
		}
		else {
			pw.write("0");
		}
		
	}else {
		pw.write("1");
	}
    }
     
}
